package com.xhcl.web.controller.system;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.xhcl.common.annotation.Log;
import com.xhcl.common.enums.BusinessType;
import com.xhcl.system.domain.TGgGkzfzh;
import com.xhcl.system.service.ITGgGkzfzhService;
import com.xhcl.common.core.controller.BaseController;
import com.xhcl.common.core.domain.AjaxResult;
import com.xhcl.common.core.domain.Stree;
import com.xhcl.common.core.domain.Ztree;
import com.xhcl.framework.uitls.poi.ExcelUtil;
import com.xhcl.common.core.page.TableDataInfo;

/**
 * 国库支付局账号Controller
 * 
 * @author xhcl
 * @date 2020-08-24
 */
@Controller
@RequestMapping("/system/gkzfzh")
public class TGgGkzfzhController extends BaseController
{
    private String prefix = "system/gkzfzh";

    @Autowired
    private ITGgGkzfzhService tGgGkzfzhService;

    @RequiresPermissions("system:gkzfzh:view")
    @GetMapping()
    public String gkzfzh()
    {
        return prefix + "/gkzfzh";
    }

    /**
     * 查询国库支付局账号列表
     */
    @RequiresPermissions("system:gkzfzh:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TGgGkzfzh tGgGkzfzh)
    {
        startPage();
        List<TGgGkzfzh> list = tGgGkzfzhService.selectTGgGkzfzhList(tGgGkzfzh);
        return getDataTable(list);
    }

    /**
     * 导出国库支付局账号列表
     */
    @RequiresPermissions("system:gkzfzh:export")
    @Log(title = "国库支付局账号", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TGgGkzfzh tGgGkzfzh)
    {
        List<TGgGkzfzh> list = tGgGkzfzhService.selectTGgGkzfzhList(tGgGkzfzh);
        ExcelUtil<TGgGkzfzh> util = new ExcelUtil<TGgGkzfzh>(TGgGkzfzh.class);
        return util.exportExcel(list, "gkzfzh");
    }

    /**
     * 新增国库支付局账号
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存国库支付局账号
     */
    @RequiresPermissions("system:gkzfzh:add")
    @Log(title = "国库支付局账号", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TGgGkzfzh tGgGkzfzh)
    {
        return toAjax(tGgGkzfzhService.insertTGgGkzfzh(tGgGkzfzh));
    }

    /**
     * 修改国库支付局账号
     */
    @GetMapping("/edit/{bm}")
    public String edit(@PathVariable("bm") String bm, ModelMap mmap)
    {
        TGgGkzfzh tGgGkzfzh = tGgGkzfzhService.selectTGgGkzfzhById(bm);
        mmap.put("tGgGkzfzh", tGgGkzfzh);
        return prefix + "/edit";
    }

    /**
     * 修改保存国库支付局账号
     */
    @RequiresPermissions("system:gkzfzh:edit")
    @Log(title = "国库支付局账号", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TGgGkzfzh tGgGkzfzh)
    {
        return toAjax(tGgGkzfzhService.updateTGgGkzfzh(tGgGkzfzh));
    }

    /**
     * 删除国库支付局账号
     */
    @RequiresPermissions("system:gkzfzh:remove")
    @Log(title = "国库支付局账号", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tGgGkzfzhService.deleteTGgGkzfzhByIds(ids));
    }
    
    /**
     * 选择国库支付局账号树
     */
    @GetMapping(value = { "/selectGkzfzhTree/{bm}", "/selectGkzfzhTree/" })
    public String selectGkzfzhTree(@PathVariable(value = "bm", required = false) String bm, ModelMap mmap)
    {
        if (StringUtils.isNotEmpty(bm))
        {
            mmap.put("tGgGkzfzh", tGgGkzfzhService.selectTGgGkzfzhById(bm));
        }
        return prefix + "/tree";
    }

    /**
     * 加载国库支付局账号树列表
     */
    @GetMapping("/treeData")
    @ResponseBody
    public List<Stree> treeData()
    {
        List<Stree> ztrees = tGgGkzfzhService.selectTGgGkzfzhTree();
        return ztrees;
    }
}
